]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Move ShellDrawingArea to StDrawingArea
authorColin Walters <walters@verbum.org>
Sat, 14 Nov 2009 21:39:22 +0000 (16:39 -0500)
committerColin Walters <walters@verbum.org>
Mon, 23 Nov 2009 19:33:48 +0000 (14:33 -0500)
It's nicer to have ShellDrawingArea as a St widget so it can
participate more cleanly in CSS styling, such as queuing a redraw
automatically on style changes, and allowing subclasses to use
CSS styling.

https://bugzilla.gnome.org/show_bug.cgi?id=602131

js/ui/altTab.js
js/ui/appIcon.js
src/Makefile-st.am
src/Makefile.am
src/shell-drawing-area.c [deleted file]
src/shell-drawing-area.h [deleted file]
src/shell-drawing.c
src/shell-drawing.h
src/st/st-drawing-area.c [new file with mode: 0644]
src/st/st-drawing-area.h [new file with mode: 0644]

index dd77266316aba4d8b6dc1fd6b8b4ef1d9b0ddec7..add986fb8358725120550c96bf8e48054d72a37e 100644 (file)
@@ -686,7 +686,7 @@ AppSwitcher.prototype = {
         appIcon.actor.reactive = false;
 
         let n = this._arrows.length;
-        let arrow = new Shell.DrawingArea();
+        let arrow = new St.DrawingArea();
         arrow.connect('redraw', Lang.bind(this,
             function (area, texture) {
                 Shell.draw_box_pointer(texture, Shell.PointerDirection.DOWN,
index 571e05097c8d543045867311ea25593e0eb1963c..5202a1da62613e1ae5c1d29c768c4c97fbd77777 100644 (file)
@@ -307,7 +307,7 @@ AppIconMenu.prototype = {
         this._windowContainer.connect('leave-event', Lang.bind(this, this._onMenuLeave));
         this._windowContainer.connect('button-release-event', Lang.bind(this, this._onMenuButtonRelease));
 
-        this._arrow = new Shell.DrawingArea();
+        this._arrow = new St.DrawingArea();
         this._arrow.connect('redraw', Lang.bind(this, function (area, texture) {
             Shell.draw_box_pointer(texture,
                                    this._type == MenuType.ON_RIGHT ? Shell.PointerDirection.LEFT : Shell.PointerDirection.UP,
index 9cb69f552baa6527ac839772de6b8243307f724b..618e334f5aeacdc0b9f1f2233c667dc6dbb6adf2 100644 (file)
@@ -73,6 +73,7 @@ st_source_h =                                 \
     st/st-box-layout-child.h                   \
     st/st-button.h                             \
     st/st-clipboard.h                          \
+    st/st-drawing-area.h        \
     st/st-entry.h                              \
     st/st-im-text.h                            \
     st/st-label.h                              \
@@ -109,6 +110,7 @@ st_source_c =                                       \
     st/st-box-layout-child.c                   \
     st/st-button.c                             \
     st/st-clipboard.c                          \
+    st/st-drawing-area.c        \
     st/st-entry.c                              \
     st/st-im-text.c                            \
     st/st-label.c                              \
index 4b11e83f31c9160b2faf05f01d158bc830a8e98b..ed9ae604198f2835811670b20a62defbdea88060 100644 (file)
@@ -67,8 +67,6 @@ libgnome_shell_la_SOURCES =                   \
        shell-button-box.h           \
        shell-drawing.c            \
        shell-drawing.h            \
-       shell-drawing-area.c                    \
-       shell-drawing-area.h                    \
        shell-embedded-window.c                 \
        shell-embedded-window.h                 \
        shell-embedded-window-private.h         \
diff --git a/src/shell-drawing-area.c b/src/shell-drawing-area.c
deleted file mode 100644 (file)
index 04505bb..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/**
- * SECTION:shell-drawing-area
- * @short_description: A dynamically-sized Cairo drawing area
- *
- * #ShellDrawingArea is similar to #ClutterCairoTexture in that
- * it allows drawing via Cairo; the primary difference is that
- * it is dynamically sized.  To use, connect to the @redraw
- * signal, and inside the signal handler, call
- * clutter_cairo_texture_create() to begin drawing.
- */
-
-#include "shell-drawing-area.h"
-
-#include <clutter/clutter.h>
-#include <gtk/gtk.h>
-#include <cairo.h>
-
-G_DEFINE_TYPE(ShellDrawingArea, shell_drawing_area, CLUTTER_TYPE_GROUP);
-
-struct _ShellDrawingAreaPrivate {
-  ClutterCairoTexture *texture;
-};
-
-/* Signals */
-enum
-{
-  REDRAW,
-  LAST_SIGNAL
-};
-
-static guint shell_drawing_area_signals [LAST_SIGNAL] = { 0 };
-
-static void
-shell_drawing_area_allocate (ClutterActor          *self,
-                             const ClutterActorBox *box,
-                             ClutterAllocationFlags flags)
-{
-  ShellDrawingArea *area = SHELL_DRAWING_AREA (self);
-  int width = box->x2 - box->x1;
-  int height = box->y2 - box->y1;
-  ClutterActorBox child_box;
-
-  /* Chain up directly to ClutterActor to set actor->allocation.  We explicitly skip our parent class
-   * ClutterGroup here because we want to override the allocate function. */
-  (CLUTTER_ACTOR_CLASS (g_type_class_peek (clutter_actor_get_type ())))->allocate (self, box, flags);
-
-  child_box.x1 = 0;
-  child_box.x2 = width;
-  child_box.y1 = 0;
-  child_box.y2 = height;
-
-  clutter_actor_allocate (CLUTTER_ACTOR (area->priv->texture), &child_box, flags);
-  if (width > 0 && height > 0)
-    {
-      clutter_cairo_texture_set_surface_size (area->priv->texture,
-                                              width, height);
-      g_signal_emit (G_OBJECT (self), shell_drawing_area_signals[REDRAW], 0,
-                     area->priv->texture);
-    }
-}
-
-static void
-shell_drawing_area_class_init (ShellDrawingAreaClass *klass)
-{
-  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-  ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
-
-  actor_class->allocate = shell_drawing_area_allocate;
-
-  shell_drawing_area_signals[REDRAW] =
-    g_signal_new ("redraw",
-                  G_TYPE_FROM_CLASS (klass),
-                  G_SIGNAL_RUN_LAST,
-                  G_STRUCT_OFFSET (ShellDrawingAreaClass, redraw),
-                  NULL, NULL,
-                  g_cclosure_marshal_VOID__OBJECT,
-                  G_TYPE_NONE, 1, G_TYPE_OBJECT);
-
-  g_type_class_add_private (gobject_class, sizeof (ShellDrawingAreaPrivate));
-}
-
-static void
-shell_drawing_area_init (ShellDrawingArea *area)
-{
-  area->priv = G_TYPE_INSTANCE_GET_PRIVATE (area, SHELL_TYPE_DRAWING_AREA,
-                                            ShellDrawingAreaPrivate);
-  area->priv->texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (1, 1));
-  clutter_container_add_actor (CLUTTER_CONTAINER (area), CLUTTER_ACTOR (area->priv->texture));
-}
-
-/**
- * shell_drawing_area_get_texture:
- *
- * Return Value: (transfer none):
- */
-ClutterCairoTexture *
-shell_drawing_area_get_texture (ShellDrawingArea *area)
-{
-  return area->priv->texture;
-}
diff --git a/src/shell-drawing-area.h b/src/shell-drawing-area.h
deleted file mode 100644 (file)
index 9cc0f8b..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-#ifndef __SHELL_DRAWING_AREA_H__
-#define __SHELL_DRAWING_AREA_H__
-
-#include <clutter/clutter.h>
-#include <gtk/gtk.h>
-
-#define SHELL_TYPE_DRAWING_AREA                 (shell_drawing_area_get_type ())
-#define SHELL_DRAWING_AREA(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), SHELL_TYPE_DRAWING_AREA, ShellDrawingArea))
-#define SHELL_DRAWING_AREA_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), SHELL_TYPE_DRAWING_AREA, ShellDrawingAreaClass))
-#define SHELL_IS_DRAWING_AREA(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SHELL_TYPE_DRAWING_AREA))
-#define SHELL_IS_DRAWING_AREA_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), SHELL_TYPE_DRAWING_AREA))
-#define SHELL_DRAWING_AREA_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), SHELL_TYPE_DRAWING_AREA, ShellDrawingAreaClass))
-
-typedef struct _ShellDrawingArea        ShellDrawingArea;
-typedef struct _ShellDrawingAreaClass   ShellDrawingAreaClass;
-
-typedef struct _ShellDrawingAreaPrivate ShellDrawingAreaPrivate;
-
-struct _ShellDrawingArea
-{
-    ClutterGroup parent;
-
-    ShellDrawingAreaPrivate *priv;
-};
-
-struct _ShellDrawingAreaClass
-{
-    ClutterGroupClass parent_class;
-
-    void (*redraw) (ShellDrawingArea *area, ClutterCairoTexture *texture);
-};
-
-GType shell_drawing_area_get_type (void) G_GNUC_CONST;
-
-ClutterCairoTexture *shell_drawing_area_get_texture (ShellDrawingArea *area);
-
-#endif /* __SHELL_DRAWING_AREA_H__ */
index 69c47b940e44359c1c9b6d74d49b0b15b62d10c8..78a7f54d57a7273a6ab27b8e452f783004a085e8 100644 (file)
@@ -3,102 +3,6 @@
 #include "shell-drawing.h"
 #include <math.h>
 
-/**
- * shell_create_vertical_gradient:
- * @top: the color at the top
- * @bottom: the color at the bottom
- *
- * Creates a vertical gradient actor.
- *
- * Return value: (transfer none): a #ClutterCairoTexture actor with the
- *               gradient. The texture actor is floating, hence (transfer none).
- */
-ClutterCairoTexture *
-shell_create_vertical_gradient (ClutterColor *top,
-                                ClutterColor *bottom)
-{
-  ClutterCairoTexture *texture;
-  cairo_t *cr;
-  cairo_pattern_t *pattern;
-
-  /* Draw the gradient on an 8x8 pixel texture. Because the gradient is drawn
-   * from the uppermost to the lowermost row, after stretching 1/16 of the
-   * texture height has the top color and 1/16 has the bottom color. The 8
-   * pixel width is chosen for reasons related to graphics hardware internals.
-   */
-  texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (8, 8));
-  cr = clutter_cairo_texture_create (texture);
-
-  pattern = cairo_pattern_create_linear (0, 0, 0, 8);
-  cairo_pattern_add_color_stop_rgba (pattern, 0,
-                                     top->red / 255.,
-                                     top->green / 255.,
-                                     top->blue / 255.,
-                                     top->alpha / 255.);
-  cairo_pattern_add_color_stop_rgba (pattern, 1,
-                                     bottom->red / 255.,
-                                     bottom->green / 255.,
-                                     bottom->blue / 255.,
-                                     bottom->alpha / 255.);
-
-  cairo_set_source (cr, pattern);
-  cairo_paint (cr);
-
-  cairo_pattern_destroy (pattern);
-  cairo_destroy (cr);
-
-  return texture;
-}
-
-/**
- * shell_create_horizontal_gradient:
- * @left: the color on the left
- * @right: the color on the right
- *
- * Creates a horizontal gradient actor.
- *
- * Return value: (transfer none): a #ClutterCairoTexture actor with the
- *               gradient. The texture actor is floating, hence (transfer none).
- */
-ClutterCairoTexture *
-shell_create_horizontal_gradient (ClutterColor *left,
-                                  ClutterColor *right)
-{
-  ClutterCairoTexture *texture;
-  cairo_t *cr;
-  cairo_pattern_t *pattern;
-
-  /* Draw the gradient on an 8x1 pixel texture. Because the gradient is drawn
-   * from the left to the right column, after stretching 1/16 of the
-   * texture width has the left side color and 1/16 has the right side color.
-   * There is no reason to use the 8 pixel height that would be similar to the
-   * reason we are using the 8 pixel width for the vertical gradient, so we
-   * are just using the 1 pixel height instead.
-   */
-  texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (8, 1));
-  cr = clutter_cairo_texture_create (texture);
-
-  pattern = cairo_pattern_create_linear (0, 0, 8, 0);
-  cairo_pattern_add_color_stop_rgba (pattern, 0,
-                                     left->red / 255.,
-                                     left->green / 255.,
-                                     left->blue / 255.,
-                                     left->alpha / 255.);
-  cairo_pattern_add_color_stop_rgba (pattern, 1,
-                                     right->red / 255.,
-                                     right->green / 255.,
-                                     right->blue / 255.,
-                                     right->alpha / 255.);
-
-  cairo_set_source (cr, pattern);
-  cairo_paint (cr);
-
-  cairo_pattern_destroy (pattern);
-  cairo_destroy (cr);
-
-  return texture;
-}
-
 void
 shell_draw_clock (ClutterCairoTexture *texture,
                   int                  hour,
index eae39fc3815f5c5250c630ab5974f37c43aa14fb..4b48d11c205dacbf4caf11a525e109a6e077a021 100644 (file)
@@ -7,12 +7,6 @@
 
 G_BEGIN_DECLS
 
-ClutterCairoTexture *shell_create_vertical_gradient (ClutterColor *top,
-                                                     ClutterColor *bottom);
-
-ClutterCairoTexture *shell_create_horizontal_gradient (ClutterColor *left,
-                                                       ClutterColor *right);
-
 typedef enum {
   SHELL_POINTER_UP,
   SHELL_POINTER_DOWN,
diff --git a/src/st/st-drawing-area.c b/src/st/st-drawing-area.c
new file mode 100644 (file)
index 0000000..4391ac1
--- /dev/null
@@ -0,0 +1,125 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/**
+ * SECTION:st-drawing-area
+ * @short_description: A dynamically-sized Cairo drawing area
+ *
+ * #StDrawingArea is similar to #ClutterCairoTexture in that
+ * it allows drawing via Cairo; the primary difference is that
+ * it is dynamically sized.  To use, connect to the #StDrawingArea::redraw
+ * signal, and inside the signal handler, call
+ * clutter_cairo_texture_create() to begin drawing.  The
+ * #StDrawingArea::redraw signal will be emitted by default when the area is
+ * resized or the CSS style changes; you can use the
+ * st_drawing_area_emit_redraw() as well.
+ */
+
+#include "st-drawing-area.h"
+
+#include <cairo.h>
+
+G_DEFINE_TYPE(StDrawingArea, st_drawing_area, ST_TYPE_BIN);
+
+struct _StDrawingAreaPrivate {
+  ClutterCairoTexture *texture;
+};
+
+/* Signals */
+enum
+{
+  REDRAW,
+  LAST_SIGNAL
+};
+
+static guint st_drawing_area_signals [LAST_SIGNAL] = { 0 };
+
+static void
+st_drawing_area_allocate (ClutterActor          *self,
+                          const ClutterActorBox *box,
+                          ClutterAllocationFlags flags)
+{
+  StThemeNode *theme_node;
+  ClutterActorBox content_box;
+  StDrawingArea *area = ST_DRAWING_AREA (self);
+  int width = box->x2 - box->x1;
+  int height = box->y2 - box->y1;
+
+  (CLUTTER_ACTOR_CLASS (st_drawing_area_parent_class))->allocate (self, box, flags);
+
+  theme_node = st_widget_get_theme_node (ST_WIDGET (self));
+
+  st_theme_node_get_content_box (theme_node, box, &content_box);
+
+  if (width > 0 && height > 0)
+    {
+      clutter_cairo_texture_set_surface_size (area->priv->texture,
+                                              content_box.x2 - content_box.x1,
+                                              content_box.y2 - content_box.y1);
+      g_signal_emit (G_OBJECT (self), st_drawing_area_signals[REDRAW], 0,
+                     area->priv->texture);
+    }
+}
+
+static void
+st_drawing_area_style_changed (StWidget  *self)
+{
+  (ST_WIDGET_CLASS (st_drawing_area_parent_class))->style_changed (self);
+
+  st_drawing_area_emit_redraw (ST_DRAWING_AREA (self));
+}
+
+static void
+st_drawing_area_class_init (StDrawingAreaClass *klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
+  StWidgetClass *widget_class = ST_WIDGET_CLASS (klass);
+
+  actor_class->allocate = st_drawing_area_allocate;
+  widget_class->style_changed = st_drawing_area_style_changed;
+
+  st_drawing_area_signals[REDRAW] =
+    g_signal_new ("redraw",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (StDrawingAreaClass, redraw),
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__OBJECT,
+                  G_TYPE_NONE, 1, CLUTTER_TYPE_CAIRO_TEXTURE);
+
+  g_type_class_add_private (gobject_class, sizeof (StDrawingAreaPrivate));
+}
+
+static void
+st_drawing_area_init (StDrawingArea *area)
+{
+  area->priv = G_TYPE_INSTANCE_GET_PRIVATE (area, ST_TYPE_DRAWING_AREA,
+                                            StDrawingAreaPrivate);
+  area->priv->texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (1, 1));
+  clutter_container_add_actor (CLUTTER_CONTAINER (area), CLUTTER_ACTOR (area->priv->texture));
+}
+
+/**
+ * st_drawing_area_get_texture:
+ *
+ * Return Value: (transfer none):
+ */
+ClutterCairoTexture *
+st_drawing_area_get_texture (StDrawingArea *area)
+{
+  return area->priv->texture;
+}
+
+/**
+ * st_drawing_area_emit_redraw:
+ * @area: A #StDrawingArea
+ *
+ * Immediately emit a redraw signal.  Useful if
+ * some parameters for the area being drawn other
+ * than the size or style have changed.
+ */
+void
+st_drawing_area_emit_redraw (StDrawingArea *area)
+{
+  g_signal_emit ((GObject*)area, st_drawing_area_signals[REDRAW], 0, area->priv->texture);
+}
diff --git a/src/st/st-drawing-area.h b/src/st/st-drawing-area.h
new file mode 100644 (file)
index 0000000..3608372
--- /dev/null
@@ -0,0 +1,39 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+#ifndef __ST_DRAWING_AREA_H__
+#define __ST_DRAWING_AREA_H__
+
+#include "st-bin.h"
+
+#define ST_TYPE_DRAWING_AREA                 (st_drawing_area_get_type ())
+#define ST_DRAWING_AREA(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), ST_TYPE_DRAWING_AREA, StDrawingArea))
+#define ST_DRAWING_AREA_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), ST_TYPE_DRAWING_AREA, StDrawingAreaClass))
+#define ST_IS_DRAWING_AREA(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ST_TYPE_DRAWING_AREA))
+#define ST_IS_DRAWING_AREA_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), ST_TYPE_DRAWING_AREA))
+#define ST_DRAWING_AREA_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), ST_TYPE_DRAWING_AREA, StDrawingAreaClass))
+
+typedef struct _StDrawingArea        StDrawingArea;
+typedef struct _StDrawingAreaClass   StDrawingAreaClass;
+
+typedef struct _StDrawingAreaPrivate StDrawingAreaPrivate;
+
+struct _StDrawingArea
+{
+    StBin parent;
+
+    StDrawingAreaPrivate *priv;
+};
+
+struct _StDrawingAreaClass
+{
+    StBinClass parent_class;
+
+    void (*redraw) (StDrawingArea *area, ClutterCairoTexture *texture);
+};
+
+GType st_drawing_area_get_type (void) G_GNUC_CONST;
+
+ClutterCairoTexture *st_drawing_area_get_texture (StDrawingArea *area);
+
+void st_drawing_area_emit_redraw (StDrawingArea *area);
+
+#endif /* __ST_DRAWING_AREA_H__ */